package com.reportes;
import  com.clases.*;



import java.util.ArrayList;

import org.achartengine.chart.PointStyle;
import org.achartengine.model.TimeSeries;
import org.achartengine.model.XYMultipleSeriesDataset;
import org.achartengine.renderer.XYMultipleSeriesRenderer;
import org.achartengine.renderer.XYSeriesRenderer;

import android.graphics.Color;

public class Venta_General 
{
	private XYMultipleSeriesDataset dataset = null;
	private XYMultipleSeriesRenderer mRender = null;
	
	
	public XYMultipleSeriesDataset getDataset () {return this.dataset;}
	
	public XYMultipleSeriesRenderer getRenders () {	return this.mRender;}
	
	public ArrayList<Venta> ventas = new ArrayList<Venta>(); 
	
	/*public int [] anno = {2006,2007,2008,2009,2010,2011,2012};
	public int [] mes = {1,2,3,4,5,6};
	public int [] cantidad = {20000,30000,10000,50000,40000,45000,20100};
	int mesInicial, int mesFinal, int anInicial, int anFinal, String ubicacion */
	
	public void llenarArreglo(){
		
		int anno = 2010; 
		
		for(int i=0; i<36;i++)
		{
			Venta v = new Venta();
			if (i<12) v.anno=anno;  
			if (i>=12 && i<24) v.anno=anno+1;
			if (i>=24 && i<36) v.anno=anno+2;
			
			v.mes = (i % 12)+1;
			
			v.monto = v.anno*100+v.mes;
			
			ventas.add(v);
		}
		
	}
	
	
	public void obtenerAnuales (int anInicial, int anFinal)
	{

		TimeSeries series = new TimeSeries("Ventas Anuales");
		llenarArreglo();
		
		
		int diferencia = anFinal - anInicial + 1;
		
		
		for (int i= 0; i < diferencia; i++)
		{
			int monto = 0;
			int an = anInicial+i;
			
			int cont = 0;
			while(cont<ventas.size()){
				
				if (an == ventas.get(cont).anno) monto = monto+ventas.get(cont).monto; 
				cont++;
			}
			
			series.add(an,monto);
		}
		
		/*series.add(2010,245002);
		series.add(2011,245600);
		series.add(2012,245950);*/
		
		
		dataset = new XYMultipleSeriesDataset();
		dataset.addSeries(series);
		
		XYSeriesRenderer render = new XYSeriesRenderer();
		render.setDisplayChartValues(true);
		render.setColor(Color.BLACK);
		render.setPointStyle(PointStyle.SQUARE);
		render.setFillPoints(true);
		
		mRender = new XYMultipleSeriesRenderer();
		mRender.addSeriesRenderer(render);
		mRender.setChartTitle("Ventas Totales");
	}
	
	public void obtenerTrimestrales ()
	{
		int [] x = {1,2,3,4,5,6};
		int [] y = {21000,12000,23000,56000,23000,78000,12100};
		
		TimeSeries series = new TimeSeries("Ventas Trimestrales");
		for (int i= 0; i < x.length; i++)
		{
			series.add(x[i],y[i]);
		}
		
		dataset = new XYMultipleSeriesDataset();
		dataset.addSeries(series);
		
		XYSeriesRenderer render = new XYSeriesRenderer();
		render.setDisplayChartValues(true);
		render.setColor(Color.BLACK);
		render.setPointStyle(PointStyle.SQUARE);
		render.setFillPoints(true);
		
		mRender = new XYMultipleSeriesRenderer();
		mRender.addSeriesRenderer(render);
		mRender.setChartTitle("Ventas Totales");
	}
	
	public void obtenerMensuales ()
	{
		int [] x = {1,2,3,4,5,6};
		int [] y = {54000,21000,26000,21000,14000,68000,90100};
		
		TimeSeries series = new TimeSeries("Ventas Mensuales");
		for (int i= 0; i < x.length; i++)
		{
			series.add(x[i],y[i]);
		}
		
		dataset = new XYMultipleSeriesDataset();
		dataset.addSeries(series);
		
		XYSeriesRenderer render = new XYSeriesRenderer();
		render.setDisplayChartValues(true);
		render.setColor(Color.BLACK);
		render.setPointStyle(PointStyle.SQUARE);
		render.setFillPoints(true);
		
		mRender = new XYMultipleSeriesRenderer();		
		mRender.addSeriesRenderer(render);
		mRender.setChartTitle("Ventas Totales");
	}

}